<?php

namespace App\Jobs;

use App\Models\NewTemplate;

class saveNewTemplete extends Job
{
    
    private $industryId;
    private $ppmc;
    private $xmys;
    private $xmtj;
    private $xmjs;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($ppmc, $xmys, $xmtj, $xmjs)
    {
        $this->ppmc = $ppmc;
        $this->xmys = $xmys;
        $this->xmtj = $xmtj;
        $this->xmjs = $xmjs;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if(empty($this->ppmc) or (empty($this->xmys) and empty($this->xmtj) and empty($this->xmjs)) ) {
            return 0;
        }
        NewTemplate::create([
            'advantage' => $this->formatContent($this->xmys, $this->ppmc),
            'condition' => $this->formatContent($this->xmtj, $this->ppmc),
            'introduce' => $this->formatContent($this->xmjs, $this->ppmc),
        ]);
        return 0;
    }
        
    public function formatContent($content, $brandName) {
        $format = str_replace($brandName, "{name}", $content);
        return $format;
    }
}
